﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;

namespace CodeCounsel.Office.WordSourceViewer
{
    public partial class Ribbon : OfficeRibbon
    {
        public Ribbon()
        {
            InitializeComponent();
        }

        private void Ribbon_Load(object sender, RibbonUIEventArgs e)
        {
            Globals.ThisAddIn.TaskPaneManager.ManageToggleButton(viewTaskPaneButton);
            showFullSourceField.Checked = Globals.ThisAddIn.ShowFullSource;
        }

        private void refreshButton_Click(object sender, RibbonControlEventArgs e)
        {
            TaskPane activePane = Globals.ThisAddIn.TaskPaneManager.GetCurrentTaskPane();
            if (activePane != null &&
                activePane.Document == Globals.ThisAddIn.Application.Selection.Document)
            {
                activePane.RefreshSource(Globals.ThisAddIn.Application.Selection.WordOpenXML);                
            }
        }

        private void copyButton_Click(object sender, RibbonControlEventArgs e)
        {
            TaskPane activePane = Globals.ThisAddIn.TaskPaneManager.GetCurrentTaskPane();
            if (activePane != null)                
            {
                string wml = activePane.GetWordprocessingML();
                if (String.IsNullOrEmpty(wml) == false)
                {
                    object missing = Type.Missing;
                    Globals.ThisAddIn.Application.Selection.InsertXML(
                        wml, ref missing);
                }
            }
        }

        private void showFullSourceField_Click(object sender, RibbonControlEventArgs e)
        {
            Globals.ThisAddIn.ShowFullSource = showFullSourceField.Checked;
            Globals.ThisAddIn.ClearTaskPanes();
        }
    }
}
